<!DOCTYPE html>
<html lang="zh">
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/header :: header(~{::title},~{::link},~{})">
    <title>点餐</title>
    <link rel="icon" th:href="@{/assets/img/lcxm.ico}" type="image/ico">
</head>
<body class="body">
<!--导航-->
<div class="container-fluid">

    <div class="row">
        <div style="margin-top: 20px;"></div>
        <div class="row">

            <form class="form-horizontal validate" role="form" method="post" th:action="@{/jira/save}"
                  onsubmit="return checkForm(this);">

                <!-- 操作信息提示的地方 -->
                <div th:if="${remind}" class="alert alert-${ remind.level  }"
                     th:classappend="'alert-' + ${remind.level}">
                    <button data-dismiss="alert" class="close" type="button">
                        <i class="glyphicon glyphicon-remove"></i>
                    </button>
                    <span th:remove="tag" th:utext="${ remind.message }"></span>
                </div>

                <div class="form-group">
                    <label for="projectId" class="col-md-2 col-sm-2 control-label">所属项目*</label>
                    <div class="col-sm-9  col-md-9  ">
                        <select class="form-control " id="projectId" name="projectId"
                                onchange="fillJiraPrefix(this)"
                                th:attr="data-value=${entity?.projectId}"
                                data-rule-required="true" >
                            <option value="">--请选择项目--</option>
                            <option th:each="item:${projects}" th:value="${item.id}" th:text="${item.text + ' (' + item.pid+')'}" th:attr="data-jira-prefix=${item.pid}"></option>
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <label for="code" class="col-md-2 col-sm-2 control-label">jira号</label>
                    <div class="col-sm-9  col-md-9  ">
                        <input type="hidden" class="form-control" id="id" name="id" th:value="${entity?.id}"/>
                        <input type="text" class="form-control" id="code" name="code" th:value="${entity?.code}"
                               data-rule-required="true"
                               onBlur="checkJiraPrefix(this)"
                               onFocus="checkProject(this)"
                               placeholder="jira号唯一" autocomplete="off"/>
                    </div>
                </div>


            </form>
        </div>


    </div>
</div>

<!-- 引入通用js-->
<div th:replace="common/footer :: connomjs"></div>
<script>
    function checkForm(form) {

        let formJson = $("form").formJson();
        if (!common.validateForm(formJson)) {
            $.alert('请完整填写信息');
            return false;
        }
        return true;
    };

    function fillJiraPrefix(event){
        let prefix = $("#projectId option:selected").data("jiraPrefix");
        if (prefix) {
            $("#code").val(prefix);
        }
    }

    function checkProject(event) {
        var jira = event.value;
        var projectId = $("#projectId").val();
        if (!projectId) {
            $.alert('请先选择项目');
        }
    }
    function checkJiraPrefix(event) {
        let jira = event.value;
        let prefix = $("#projectId option:selected").data("jiraPrefix");
        if (jira && prefix) {
            if (!jira.startsWith(prefix)) {
                $.alert('jira号须符合项目的jira前缀要求!');
                $("#code").val("");
            }
        }
    }


</script>

</body>
</html>